package com.edu.koTA07.takingOrder;

import java.util.ArrayList;

import com.edu.koTA07.bean.CustomerBean;
import com.edu.koTA07.utils.CustomerUtils;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;
import android.widget.AdapterView.OnItemSelectedListener;

public class AddToko extends Activity {	
	public static final String KEY_RADIO_GROUP="RadioButton";
	private static EditText namaToko, namaPemilik , alamat, telepon;
	private static Button toko ;
	private static Spinner spinner;
	CustomerBean customer;
	CustomerUtils util;
	ArrayList<CustomerBean> getAllCustomer;
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.add_toko);
        customer = new CustomerBean();
        util = new CustomerUtils(this);
        getAllCustomer = new ArrayList<CustomerBean>();
        getAllCustomer = util.loadData();
        int banyakDataCustomer = getAllCustomer.size();
        customer.setIDCustomer("C"+banyakDataCustomer);
        
        namaToko = (EditText)findViewById(R.id.namaToko);
        customer.setNamaToko(namaToko.getText().toString());
        namaPemilik = (EditText)findViewById(R.id.namaPemilik);
        customer.setNamaPemilik(namaPemilik.getText().toString());
        alamat = (EditText)findViewById(R.id.alamat);
        customer.setAlamatCustomer(alamat.getText().toString());
        telepon = (EditText)findViewById(R.id.telepon);
        customer.setTelepon(telepon.getText().toString());
        
        spinner = (Spinner) findViewById(R.id.spinner);
        ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
                this, R.array.hari_array, android.R.layout.simple_spinner_item);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner.setAdapter(adapter);        
        spinner.setOnItemSelectedListener(new OnItemSelectedListener(){

			public void onItemSelected(AdapterView<?> arg0, View arg1,
					int arg2, long arg3) {
				// TODO Auto-generated method stub
				customer.setTipeHariKunjungan(spinner.getSelectedItem().toString());
			}

			public void onNothingSelected(AdapterView<?> arg0) {
				// TODO Auto-generated method stub
				
			}
        	
        });
//        nextAct = (String) spinner.getSelectedItem();
//        
        
        
         toko = (Button) findViewById(R.id.submit_addToko);		
         toko.setOnClickListener(new OnClickListener() {
	
			public void onClick(View v) {					
				new XmlFileCreatorCustomer(customer);
 				Toast.makeText(AddToko.this,
 						"Data telah tersimpan...", Toast.LENGTH_SHORT)
 						.show();
 				
 	     		Intent Intent = new Intent(AddToko.this,
 						Main.class);
				startActivity(Intent);
				finish();
			}
		});
    }  
}   